//
//  HLDelegateView.m
//  MVVMFoundation
//
//  Created by hulinhu on 2017/12/21.
//  Copyright © 2017年 hulinhu. All rights reserved.
//

#import "HLDelegateView.h"

@implementation HLDelegateView {
    
    NSInteger count;
}


-(RACCommand *)btnCommand {
    if (!_btnCommand) {
         RACCommand *command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
            return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
                [subscriber sendNext:@"请求数据"];
                [subscriber sendCompleted];
                return nil;
            }];
        }];
        _btnCommand = command;
    }
    return _btnCommand;
}


-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    // 判断代理信号是否有值
     // 方式一
    if (self.delegateSignal) {
        // 有值，才需要发送 UISwitch 的状态
        [self.delegateSignal sendNext:@(1)];
    }

    // 方式二
    [self singbtnClick:@"监听代理回调"];
    
    count ++;
    NSLog(@"---- %ld",count);
    // 3.执行命令
    RACSignal *signal1 = [self.btnCommand execute:@(count)];
    NSLog(@" --- %p",signal1);

    
 
}


-(void)singbtnClick:(NSString *)index {
    
}

@end
